# -*- coding: utf-8 -*-
import threading

from django.shortcuts import HttpResponseRedirect

from bsfault.commen.interface import operator_info, fault_info

'''
拦截器
'''

try:

    from django.utils.deprecation import MiddlewareMixin  # Django 1.10.x
except ImportError:
    MiddlewareMixin = object  # Django 1.4.x - Django 1.9.x


class SimpleMiddleware(MiddlewareMixin):
    def process_request(self, request):
        if request.path != '/login/' and request.path != '/userlogin/':
            if request.session.get('username', None):
                pass
            else:
                return HttpResponseRedirect('/login/')


'''
一天保存一次日志
'''


def fun_timer():
    fault_info()
    operator_info()
    global timer
    timer = threading.Timer(60*60, fun_timer)
    # timer = threading.Timer(60 * 60 *24, fun_timer) 24h清空一次
    timer.start()


timer = threading.Timer(60*60, fun_timer())
# timer = threading.Timer(60 * 60 *24, fun_timer)24h清空一次
timer.start()
